package com.yami.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.model.RedTokenRecord;
import com.yami.shop.dao.RedTokenRecordMapper;
import com.yami.shop.service.RedTokenRecordService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
public class RedTokenRecordServiceImpl extends ServiceImpl<RedTokenRecordMapper, RedTokenRecord> implements RedTokenRecordService {


    @Override
    public void saveBatchByTokens(String applyId,String denomId,String contenStr, String dawProductCode, Long redId) {
        List<String> tokenIds = Arrays.asList(contenStr.split(","));
        List<String> dawProdCodes = Arrays.asList(dawProductCode.split(","));
        List<RedTokenRecord> redTokenRecords = new ArrayList<>();
        for(int i = 0; i < tokenIds.size(); i++) {
            RedTokenRecord redTokenRecord = new RedTokenRecord();
            redTokenRecord.setApplyId(applyId);
            redTokenRecord.setDenomId(denomId);
            redTokenRecord.setProductCode(dawProdCodes.get(i));
            redTokenRecord.setTokensId(tokenIds.get(i));
            redTokenRecord.setRedId(redId+"");
            redTokenRecords.add(redTokenRecord);
        }
        this.saveBatch(redTokenRecords);
    }
}
